package com.ruoyi.app.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wuliu.domain.CarSource;
import com.ruoyi.web.wuliu.service.ICarSourceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 车辆发布Controller
 * 
 * @author ruoyi
 * @date 2023-12-05
 */
@RestController
@RequestMapping("/app/wuliu/source")
public class AppCarSourceController extends BaseController
{
    @Autowired
    private ICarSourceService carSourceService;

    /**
     * 查询车辆发布列表
     */
    @ApiOperation("查询车辆发布列表")
    @GetMapping("/list")
    public TableDataInfo list(CarSource carSource)
    {
        startPage();
        List<CarSource> list = carSourceService.selectCarSourceList(carSource);
        return getDataTable(list);
    }

    /**
     * 获取车辆发布详细信息
     */
    @ApiOperation("获取车辆发布详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        CarSource carSource = carSourceService.selectCarSourceById(id);
        carSource.setStatus(carSource.getStatus()+1);
        carSourceService.updateCarSource(carSource);
        return success(carSource);
    }

    /**
     * 新增车辆发布
     */
    @ApiOperation("新增车辆发布")
    @PostMapping
    public AjaxResult add(@RequestBody CarSource carSource)
    {
        return toAjax(carSourceService.insertCarSource(carSource));
    }

    /**
     * 修改车辆发布
     */
    @ApiOperation("修改车辆发布")
    @PutMapping
    public AjaxResult edit(@RequestBody CarSource carSource)
    {
        return toAjax(carSourceService.updateCarSource(carSource));
    }

    /**
     * 删除车辆发布
     */
    @ApiOperation("删除车辆发布")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carSourceService.deleteCarSourceByIds(ids));
    }
}
